package com.year_23.april;

/**
 *      300 最长递增子序列数组
 *
 *      https://leetcode.cn/problems/longest-increasing-subsequence/description/
 * @Author jsh
 * @Date 2023/4/20 23:04
 * @Version 1.0
 */
public class Day20 {

    public static void main(String[] args) {
        int[] arr =  {10,9,2,5,3,7,101,18};
        System.out.println(lengthOfLIS(arr));
    }
    /*
    * 动态规划
    * */
    public static int lengthOfLIS(int[] nums) {
        if (nums.length == 0)return 0;
        int[] dp = new int[nums.length];
        dp[0] = 1;
        int res = 1;
        /*
        *  索引以i结尾的数组，最大递增子序列数组
        * */
        for (int i = 1; i < nums.length; i++) {
            int v = nums[i];
            dp[i] = 1;
            for (int j = 0; j < i; j++) {
                if (v > nums[j])dp[i] = Math.max(dp[i], dp[j] + 1);
            }
            res = Math.max(res, dp[i]);
        }
        return res;
    }

}
